import cdkey
import MySQLdb

insert_keys=[]
key = cdkey.cdkey(6,32)
key.run()
key.cdkeys

conn = MySQLdb.connect(host="localhost",port=3306,user="root",passwd="zheng",db="zou")
cus = conn.cursor()

#create_DB_keys="create database keys;"
if not cus.execute('select count(*) from INFORMATION_SCHEMA.TABLES where table_name="cdkeys";'):
    create_DB_table_key="create table cdkeys (cdkey varchar(255));"
    cus.execute(create_DB_table_key)
#cus.execute(create_DB_keys)
#cus.execute(use_DB_keys)

for i in key.cdkeys:
    insert_keys.append("insert into cdkeys(cdkey) values('"+str(i)+"');")
#print insert_keys
for i in range(len(key.cdkeys)):
    cus.execute(insert_keys[i])
conn.commit()
cus.close()
conn.close()